package com.frost.blog.model;

import lombok.Data;

import static com.frost.blog.constants.Constant.*;

@Data
public class Result {
    private Integer code; // 200-成功 -1失败 -2未登录
    private String errMsg;
    private Object data;

    // 成功
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    // 失败
    public static Result fail(String errMsg) {
        Result result = new Result();
        result.setCode(FAIL_CODE);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }

    // 失败
    public static Result fail(Object data, String errMsg) {
        Result result = new Result();
        result.setCode(FAIL_CODE);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }

    // 未登录
    public static Result unlogin() {
        Result result = new Result();
        result.setCode(UNLOGIN_CODE);
        result.setErrMsg("用户未登录");
        result.setData(null);
        return result;
    }
}
